import config from './config'

// 发送ajax请求
export default (url,data={},method='GET')=>{
    return new Promise((resolve,reject)=>{
        wx.request({
          url:config.mobileHost+url,
          // url:config.host+url,
          data,
          method,
          header: {
            cookie: wx.getStorageSync('cookies') ? wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1):''
          },
          success:(res)=>{
            if(data.isLogin){//登录请求,将用户cookie存入
              wx.setStorage({
                key: 'cookies',
                data: res.cookies,
              })
            }
            // resolve修改promise的状态为成功状态resolved
            resolve(res.data)
          },
          fail:(err)=>{
            // resolve修改promise的状态为成功状态resolved
            // console.log('请求失败:',err);
            reject(err)
          }
        })
    })
}